package com.common.domain.entity;

import java.io.Serializable;
import java.util.Map;

/**
 * http接口返回结果类
 * @author Songyang WU
 * @param <T>
 */
public class JsonResult<T> implements Serializable {

    private static final long serialVersionUID = 6057801652159135536L;

    /** 是否成功 */
    private boolean success;

    /** 成功或失败标志,与变量success做关联:success,failure(为了兼容以往的接口) */
    private String result;

    /** 数据 */
    private T data;

    /** 数据Map */
    private Map<String,Object> dataMap;

    private Object dataObject;

    /** 信息 */
    private String info;

    public JsonResult() {
        super();
    }

    public JsonResult(T data) {
        this.data = data;
        this.success = true;
    }

    public Object getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        if (success) {
            this.result = "success";
        } else {
            this.result = "failure";
        }
        this.success = success;
    }

    /**
     * 获取 信息
     * @return info
     */
    public String getInfo() {
        return info;
    }

    /**
     * 设置 信息
     * @param info 信息
     */
    public void setInfo(String info) {
        this.info = info;
    }

    /**
     * 获取 成功或失败标志与变量success做关联:successfailure(为了兼容以往的接口)
     * @return result
     */
    public String getResult() {
        return result;
    }

    /**
     * 设置 成功或失败标志与变量success做关联:successfailure(为了兼容以往的接口)
     * @param result 成功或失败标志与变量success做关联:successfailure(为了兼容以往的接口)
     */
    public void setResult(String result) {
        this.result = result;
    }

	public Map<String, Object> getDataMap() {
		return dataMap;
	}

	public void setDataMap(Map<String, Object> dataMap) {
		this.dataMap = dataMap;
	}

	public void success(){
		setSuccess(true);
	}

	public void failure(){
		setSuccess(false);
	}

	public Object getDataObject() {
		return dataObject;
	}

	public void setDataObject(Object dataObject) {
		this.dataObject = dataObject;
	}
}
